package com.swak.telnet.transport;

import com.swak.exception.RemotingException;
import com.swak.reactivex.transport.ChannelHandler;
import com.swak.reactivex.transport.Codec;
import com.swak.reactivex.transport.NettyCodec;
import com.swak.reactivex.transport.NettyServer;
import com.swak.reactivex.transport.resources.LoopResources;
import com.swak.registry.URL;

import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;

public class TelnetServer extends NettyServer {

	public TelnetServer(URL url, LoopResources resources, ChannelHandler handler) throws RemotingException {
		super(url, resources, handler);
	}

	@Override
	protected void customChannel(SocketChannel ch) {
		ChannelPipeline pipeline = ch.pipeline();
		Codec codec = new StringCodec(getUrl());
		NettyCodec nettyCodec = new NettyCodec(codec, getUrl(), this);
		pipeline.addLast(NettyCodec.Encoder_Name, nettyCodec.getEncoder());
		pipeline.addLast(NettyCodec.Decoder_Name, nettyCodec.getDecoder());
		pipeline.addLast(NettyCodec.Upgrader_Name, new UpgradeHandler(url(), TelnetServer.this));
	}
}